package com.wwy.service.impl;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.wwy.mapper.TbOrderMapper;
import com.wwy.module.TbOrder;
import com.wwy.service.TbOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author 王伟羽
 * @program: rabbitmq
 * @description: 订单服务实现类
 * @create: 2024/11/01
 */

@Service
public class TbOrderServiceImpl implements TbOrderService {

    @Resource
    private TbOrderMapper tbOrderMapper;


    @Override
    public int insertTbOrder(String message) {
        TbOrder tbOrder = JSONObject.parseObject(message, TbOrder.class);
        if(Objects.nonNull(tbOrder)){
            //先查询看是否已经入库
            List<TbOrder> tbOrders = tbOrderMapper.selectList(tbOrder);
            if(CollectionUtils.isEmpty(tbOrders)){
                tbOrder.setId(IdUtil.objectId());
                tbOrderMapper.insert(tbOrder);
                return 1;
            }
        }
        return 0;
    }
}
